{% extends "assistant_results.html" %}
{% load humanize debate_tags i18n %}

{% block page-subnav-sections %}
  <a href="{% roundurl 'draw-display' %}" class="btn btn-outline-primary">
    <i data-feather="chevron-left"></i> {% trans "Display Draw" %}
  </a>
  <a class="btn btn-outline-primary" href="{% tournamenturl 'admin-checkin-prescan' %}">
    {% trans "Check-In Ballots" %}
  </a>
  <a class="btn btn-outline-primary" href="" data-toggle="modal" data-target="#ironSpeeches">
    {% trans "Recent 'Iron-Persons'" %}
  </a>

  <div class="modal fade" id="ironSpeeches" tabindex="-1" role="dialog"
       aria-labelledby="" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title">{% trans "Teams who have recently missed a speaker" %}</h4>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="list-group">
          {% for iron in iron_speeches %}
            <div class="list-group-item">
              <h5>
                For Current Debate
                {% if iron.venue %}
                  in Room {{ iron.venue }}
                {% endif %}
              </h5>
              {% if iron.previous_round %}
                <p class="text-warning mt-3 mb-0">
                  {% blocktrans trimmed with team=iron.team %}
                    A speaker from {{ team }} gave multiple speeches in the previous round
                  {% endblocktrans %}
                </p>
              {% endif %}
              {% if iron.current_round %}
                <p class="text-info mt-3 mb-0">
                  {% blocktrans trimmed with team=iron.team %}
                    A speaker from {{ team }} gave multiple speeches in the current round
                  {% endblocktrans %}
                </p>
              {% endif %}
            </div>
          {% empty %}
           <div class="list-group-item">
              <p class="lead text-success mb-0">
                {% trans "No known cases in the current or previous round" %}
              </p>
            </div>
          {% endfor %}
        </div>
      </div>
    </div>
  </div>

{% endblock %}

{% block page-subnav-actions %}
  {% if round.is_current %}
    <a class="btn {% if incomplete_ballots %}btn-danger disabled{% else %}btn-outline-success{% endif %} " href="{% roundurl 'tournament-complete-round-check' %}">
      {% trans "Complete Round" %} <i data-feather="chevron-right"></i>
    </a>
  {% else %}
    <div class="hidden"></div><!-- Just keeps the spacing consistent -->
  {% endif %}
{% endblock %}

{% block page-alerts-role-specific %}
  {# Overrides the assistant version of the same alert. #}

  {% trans "This page automatically updates with the new ballot entries and checkins as they occur. You will, however, need to reload it once all ballots are completed in order to advance the round." as p1 %}
  {% include "components/explainer-card.html" with type="info" %}

  {% comment %}
    Stopgap to warn user about potential database inconsistency, when trainee adjudicators
    seem to have given scores. This normally happens when an adjudicator was demoted after
    a result was entered. See: https://github.com/TabbycatDebate/tabbycat/issues/922
    This stopgap should be deleted after a more general data consistency solution is
    implemented.
  {% endcomment %}
  {% if debates_with_trainee_scoresheets %}
    {% blocktrans trimmed with debates_list=debates_with_trainee_scoresheets|join:", " count ndebates=debates_with_trainee_scoresheets|length asvar message %}
      The following debate appears to have scoresheets from trainees: {{ debates_list }}.
    {% plural %}
      The following {{ ndebates }} debates appear to have scoresheets from trainees: {{ debates_list }}.
    {% endblocktrans %}
    {% url 'admin:results_speakerscorebyadj_changelist' as editdb_speakerscorebyadj_url %}
    {% blocktrans trimmed asvar trainee_extra %}
      This can happen if you demote a panellist to trainee after a result has been
      submitted for that debate. This may indicate that there is an inconsistency
      in results data, which may cause unexpected results (or crashes). Please
      consider going to the Edit Database area and deleting the offending
      <a href="{{ editdb_speakerscorebyadj_url }}?debate_adjudicator__type__exact=T" class="alert-link">"speaker
      scores by adj" objects</a>, and then opening and resaving the result here.
    {% endblocktrans %}
    {% include "components/alert.html" with type="danger" icon="alert-octagon" extra=trainee_extra %}
  {% endif %}

  {% comment %}
    Another warning about potential database inconsistency, but this one's only
    ever happened as a consequence of direct database edits via SQL, so we've
    probably already got all the consistency checks we can reasonably have. This
    is just an extra courtesy for users who try to hack too much.
  {% endcomment %}
  {% if debates_with_multiple_confirmed_ballots_found %}
    {% blocktrans trimmed asvar message %}
      One or more debates in this round appear to have more than one confirmed
      ballot submission. This can cause unexpected results (or crashes), because
      Tabbycat assumes that each debate has at most one confirmed ballot
      submission. This inconsistency can generally only arise if you manipulate
      the database with SQL queries directly. You'll need to find the offending
      debate(s) and ballot submissions yourself in the Edit Database area, or if
      that doesn't work, you might need to find them using SQL queries directly.
    {% endblocktrans %}
    {% include "components/alert.html" with type="danger" icon="alert-octagon" %}
  {% endif %}

  {% if pref.teams_in_debate == "bp" and round.ballots_per_debate == "per-adj" %}
    {% tournamenturl 'options-tournament-section' section='debate_rules' as debate_rules_url %}
    {% blocktrans trimmed asvar message %}
      This tournament's configuration is set to <strong>British Parliamentary</strong> with <strong>one ballot per voting adjudicator</strong>. This combination isn't allowed: BP tournaments must use consensus ballots. Results can't be entered while this configuration is in place. Please <a href="{{ debate_rules_url }}">revise this tournament's configuration</a> before you try to enter results.
    {% endblocktrans %}
    {% include "components/alert.html" with type="danger" %}
  {% endif %}

  {% if pref.enable_motions and round.motion_set.count == 0 %}
    {% roundurl 'motions-edit' as motions_url %}
    {% blocktrans trimmed asvar message %}
      Currently there are no motions entered for this round, so debate results
      cannot be entered. <a href="{{ motions_url }}" class="alert-link">Add Motions.</a>
    {% endblocktrans %}
    {% include "components/alert.html" with type="danger" %}
  {% endif %}

  {% roundurl 'draw-display' as display_url %}
  {% if round.draw_status != round.STATUS_RELEASED and pref.participant_ballots != 'off' %}
    {% blocktrans trimmed asvar message %}
        Your tournament configuration allows ballots to be submitted online by adjudicators. The draw <a href="{{ display_url }}" class="alert-link">must be released</a> before they can do so for this round.
      {% endblocktrans %}
    {% include "components/alert.html" with type="danger" %}
  {% endif %}

  {% if round.draw_status != round.STATUS_RELEASED and pref.participant_feedback != 'off' %}
    {% blocktrans trimmed asvar message %}
        Your tournament configuration allows feedback to be submitted online by participants. The draw <a href="{{ display_url }}" class="alert-link">must be released</a> before they can do so for this round.
      {% endblocktrans %}
    {% include "components/alert.html" with type="danger" %}
  {% endif %}

{% endblock %}
